import { IMTableType } from "@/types/table";
import { tableActiveKey } from "./store";
export const defaultColumns = reactive<any>([
  [
    {
      title: getProxyT("base.index"),
      dataIndex: "index",
      key: "index",
    },
    {
      title: getProxyT("table239"),
      dataIndex: "aaaa",
      key: "aaaa",
    },
    {
      title: getProxyT("table242"),
      dataIndex: "bbbb",
      key: "bbbb",
    },
    {
      title: getProxyT("table243"),
      dataIndex: "cccc",
      key: "cccc",
    },
    {
      title: getProxyT("table55"),
      dataIndex: "dddd",
      key: "dddd",
    },
  ],
  [],
]);
export let columns = reactive<IMTableType[]>([
  ...defaultColumns[tableActiveKey.value],
]);
export const tablePage = renderTablePage({ total: 40 });
export const tableData = ref<any>([]);
export const tableLoading = ref(false);
const defineBodyCellMap = ({ value, text, index, column, record }) => {
  const renderAction = () => <div class="s-table-body_cell"></div>;
  return new Map([[{ key: "action" }, renderAction]]);
};
const handleRenderBodyCellTask = (props) => {
  const array = [...defineBodyCellMap(props)].filter(
    ([object]) => object.key === props.column.key
  );
  const _this = { tablePage, ...props };
  return array.map(([, value]) => value.call(_this));
};
export const checkedRecord = reactive({
  type: "checkbox",
  onChange: (recordIndexArray, recordArray) =>
    (checkedRecord.selectedRowKeys = recordIndexArray),
  selectedRowKeys: [1, 2, 9, 10],
});
export const tableConfig = () => {
  const defineTable = {
    pagination: tablePage,
    columns,
    dataSource: tableData,
    loading: tableLoading,
    rowSelection: checkedRecord,
    rowKey: (record) => record.index,
    on: {
      change(paging: { current: number; pageSize: number }) {
        tablePage.current = paging.current;
        tablePage.pageSize = paging.pageSize;
        // fetchList();
      },
    },
    tableSlot: {
      bodyCell: (props) => handleRenderBodyCellTask(props),
    },
  };
  return defineTable;
};
